package com.neu.service.impl;

import com.neu.dao.BookDao;
import com.neu.dao.PlansDao;
import com.neu.po.Book;
import com.neu.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional(readOnly = false)
public class BookServiceImpl implements BookService {
    @Autowired
    BookDao bookDao;

    @Autowired
    PlansDao plansDao;
    @Override
    public void addBook(Book book) {
        bookDao.insert(book);
    }

    @Override
    public List<Book> findAllByUserId(int userId) {
        return bookDao.selectAllByUserId(userId);
    }

    @Override
    public List<Book> findAllByTime(Date time) {
        return null;
    }

    @Override
    public void cancelBookBybookId(Integer bookId) {
        Book book = bookDao.selectById(bookId);
        System.out.println(bookId);
        System.out.println(book);
        plansDao.addBookCount(book.getPlanId());
        bookDao.deleteById(bookId);
    }
}
